/*
 * Element.cpp
 *
 *  Created on: 12 mars 2012
 *      Author: lsinapayen
 */

#include "Element.h"

Element::Element(string * nom, string * nomspace = NULL):Item(nom) {

	this->nomspace = *nomspace;
}

Element::~Element() {

}

vector<Attribut*> * Element::getAttributs()
    {
        return &attributs;
    }

/*Data * Element::getData()
    {
        return data;
    }*/

vector<Item*> * Element::getItems()
    {
        return &items;
    }

    void Element::setAttributs(vector<Attribut*> * attributs)
    {
    	vector<Attribut*>::iterator itAtts;
    	itAtts = attributs->begin();
    	while(itAtts!=attributs->end()){
    		this->attributs.push_back((*itAtts));
    		itAtts++;
    	}
    }

/*    void Element::setData(Data * data)
    {
        //this->data->setName(data->getName());
    	this->data = data;
    }*/

void Element::setItems(vector<Item*> * items)
{
	vector<Item*>::iterator itIt;
		itIt = items->begin();
		while(itIt!=items->end()){
			this->items.push_back((*itIt));
			itIt++;
		}
}


int Element::afficher(){
	vector<Item*>::iterator itIts;
	vector<Attribut*>::iterator itAtts;

	//ouverture de la balise
	cout<<"<";
	if(this->nomspace != "")
		cout<<this->nomspace<<":";
	cout<<this->name;

	itAtts = this->attributs.begin();

	//affichage de tous les attributs
	while(itAtts != this->attributs.end()){
		(*itAtts)->afficher();
		itAtts++;
	}
	//fermeture de la balise
	 cout<<">"<<endl;
	
	itIts = this->items.begin();

	while(itIts != this->items.end()){
		cout<<" ";
		(*itIts)->afficher();
		itIts++;
	}
	
	//fermeture de la balise
	 cout<<"</"<<this->name<<">"<<endl;

	return 0;
}

